use crate::models::datasource as ds;
use crate::{impl_model_convert, impl_schema_convert};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateFile {
    pub name: String,
    pub ds_id: String,
    pub kind: String,
    pub file_path: String,
    pub query: Option<String>,
    pub total: Option<i32>,
    pub last_refresh: Option<chrono::NaiveDateTime>,
}
impl_model_convert!(CreateFile => ds::file::ActiveModel {name,ds_id,kind,file_path,query});
impl_model_convert!(CreateFile => ds::core::ActiveModel { name, kind, last_refresh  });

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateServe {
    pub name: String,
    pub ds_id: String,
    pub kind: String,
    pub port: i32,
    pub host: String,
    pub username: String,
    pub password: Option<String>,
    pub schema: String,
    pub query: Option<String>,
    pub total: Option<i32>,
    pub last_refresh: Option<chrono::NaiveDateTime>,
}
impl_model_convert!(CreateServe => ds::serve::ActiveModel {name,ds_id,kind,query,schema,port,host,username,password});
impl_model_convert!(CreateServe => ds::core::ActiveModel { name, kind, last_refresh,total  });

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListItem {
    pub id: String,
    pub name: String,
    pub kind: String,
    pub total: Option<i32>,
    pub last_refresh: Option<chrono::NaiveDateTime>,
}
impl_schema_convert!(ds::core::Model => ListItem {id, name, kind, last_refresh, total});

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UpdateFile {
    pub id: String,
    pub name: String,
    pub ds_id: String,
    pub kind: String,
    pub file_path: String,
    pub query: Option<String>,
}
impl_model_convert!(UpdateFile => ds::file::ActiveModel {id,name,ds_id,kind,file_path,query});
impl_model_convert!(UpdateFile => ds::core::ActiveModel {name,kind});
impl_schema_convert!(ds::file::Model => UpdateFile {id,name,ds_id,kind,file_path,query});

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UpdateServe {
    pub id: String,
    pub name: String,
    pub ds_id: String,
    pub kind: String,
    pub port: i32,
    pub host: String,
    pub username: String,
    pub password: Option<String>,
    pub schema: String,
    pub query: Option<String>,
}
impl_model_convert!(UpdateServe => ds::serve::ActiveModel {id,name,ds_id,kind,query,schema,port,host,username,password});
impl_model_convert!(UpdateServe => ds::core::ActiveModel {name,kind});
impl_schema_convert!(ds::serve::Model => UpdateServe{id,name,ds_id,kind,query,schema,port,host,username,password});

#[derive(Debug, Serialize, Deserialize)]
pub struct Operate {
    pub id: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct DescriptionItem {
    pub id: Option<String>,
    pub ds_id: String,
    pub field_name: String,
    pub data_type: String,
    pub nullable: bool,
    pub comment: Option<String>,
    pub description: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateDsDescription {
    pub field_name: String,
    pub field_type: String,
    pub comment: String,
    pub description: String,
}
impl_model_convert!(CreateDsDescription => ds::description::ActiveModel {field_name,field_type,description,comment});
